# note --------------------------------------------------------------------

# this is one of the two master replication files for:
# umit, r. rallies around the flag-draped coffins: the electoral effects of 
# security force casualties in terror attacks. conditionally accepted (pending 
# replication) for publication in political science research and methods.
#
# the other master replication file is called analysis.do 
#
# replication requires the following directory structure:
#
# working_directory/
#  |
#  +---analysis.do
#  +---analysis.R
#  |
#  +---datasets/
#  |       data_*
#  |
#  +---figures/
#  |       
#  |
#  +---scripts/
#  |       script_*
#  |
#  \---tables/
#
# replication also requires six third-party packages, which can be installed by
# removing the leading hashes from the lines 39 to 44 below.


# set the locale temporarily to uk 1252 -----------------------------------

Sys.setlocale(category = "LC_ALL", locale = "English_United Kingdom.1252")


# install the required libraries if they are not already installed --------

# if (!require("dplyr")) install.packages("dplyr")
# if (!require("tidyr")) install.packages("tidyr")
# if (!require("ggplot2")) install.packages("ggplot2")
# if (!require("sf")) install.packages("sf")
# if (!require("ebal")) install.packages("ebal")
# if (!require("kableExtra")) install.packages("kableExtra")

# load the required libraries ---------------------------------------------

library(dplyr) # a grammar of data manipulation, cran v1.0.4
library(tidyr) # tidy messy data, cran v1.1.2
library(ggplot2) # create elegant data visualisations using the grammar of graphics, cran v3.3.3
library(sf) # simple features for r, cran v0.9-7
library(ebal) # entropy reweighting to create balanced samples, cran v0.1-6
library(kableExtra) # construct complex table with 'kable' and pipe syntax, cran v1.3.4

# source the script that plots figure 1 -----------------------------------

source("scripts/script_figure_1.R", echo = TRUE, max.deparse.length = Inf)

# source the script that plots figure 2 -----------------------------------

source("scripts/script_figure_2.R", echo = TRUE, max.deparse.length = Inf)

# source the script that plots figure 3 -----------------------------------

source("scripts/script_figure_3.R", echo = TRUE, max.deparse.length = Inf)

# source the script that plots figure 4 -----------------------------------

source("scripts/script_figure_4.R", echo = TRUE, max.deparse.length = Inf)

# source the script that creates table s4 ---------------------------------

source("scripts/script_table_s4.R", echo = TRUE, max.deparse.length = Inf)

# source the script that plots figure s1a ---------------------------------

source("scripts/script_figure_s1a.R", echo = TRUE, max.deparse.length = Inf)

# source the script that plots figure s1b ---------------------------------

source("scripts/script_figure_s1b.R", echo = TRUE, max.deparse.length = Inf)